<script type="text/javascript">    
   function search(obj) {
        $('tr').hide().filter(":contains('" +($(obj).val()) + "')").show();
   
}  
</script>
<script type="text/javascript">    
   function searchlog() {
        $.post("/cgi-bin/CDN_DM_Search.py",
  {
    Sdomain:$('#Sdomain').val(),
    logtime:$('#logtime').val(),

  },
   function(data,status){
    $("#tableDiv").html(data)
  });
   
}  
</script>
<script type="text/javascript">
  function insertdomain(){
  $.post("/CDNdmain/insert.php",
  {
    domain:$('#domain').val(),
    CP:$('#CP').val(),
    mon:"yes"
  },
   function(data,status){
    alert("Data: " + data + "\nStatus: " + status);
  });
}
</script>
<form action="/CDNdmain/changeDomainStat.php" method="post" >

<div class="row">
<div class="col-md-2" > 
<div style="position:fixed;">
  <div class="btn-group-vertical hidden-xs" style="width: 200px;">
    <button class="btn btn-default" type="submit" name="stat" value="yes">开启选中域名监控</button>
    <button class="btn btn-default" type="submit" name="stat" value="no">关闭选中域名监控</button>
    <button type="button" class="btn btn-default" onclick="$('tr').show()" value="yes">显示所有</button>
    <button type="button" class="btn btn-default" onclick="search(this)" value="yes">显示监控的主机</button>
    <button type="button" class="btn btn-default" onclick="search(this)" value="grey">显示不监控的主机</button>
    
  </div>
  <hr>
  <div class="form-group">
    <label for="name">日志筛选：</label>
    <p>日期选择：</p>
    <select class="form-control" id="logtime">
      <?php 
      $dir="/var/www/html/CDNlog";
      $file=scandir($dir);
      array_multisort($file,SORT_DESC);
      foreach ($file as $name){
        if (strpos($name,".txt")!==false){
          printf('<option value ="%s">%s</option>',$name,strstr( $name, '.', TRUE));
        }
      #echo $name;
      }
      ?>
    </select>
    <p>查询的域名：</p>
    <input type="text" id="Sdomain" class="form-control">
      <br>
    <button type="button" class="btn btn-default" onclick="searchlog()">查询日志</button>
  </div>

</div>
</div>
<div class="col-md-10" id="tableDiv"> 
<div class="row">
  <div class="col-md-3">
        <div class="input-group">
            <span class="input-group-addon">新增监控域名</span>
            <input type="text" id="domain" class="form-control">
        </div>
  </div>
  <div class="col-md-3">
        <div class="input-group">
            <span class="input-group-addon">新增域名所属CP</span>
            <input type="text" id="CP" class="form-control">
        </div>
            
  </div>
  <div class="col-md-3">
    <button type="button" id="insertB" class="btn btn-default" onclick="insertdomain()">提交</button>
  </div>
</div> 
<br>
<div class="row">
<?php
header("Content-type: text/html; charset=utf-8");
$con = mysql_connect("113.215.1.161","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
//code
mysql_select_db("mydb", $con);//选库
mysql_query("set names 'utf8'");
$result = mysql_query("SELECT * FROM CDN_domainTab ORDER BY mon DESC,flag DESC, CDN ");
echo '<table id="store" class="table-bordered table-hover table-striped" style="width:100%; text-align:center">
<tr>
<th>归属CDN</th>
<th>域名</th>
<th>CNAME</th>
<th>业务应用</th>
<th>解析结果IP</th>
<th>是否监控</th>
<th>选择主机</th>
</tr>';
while($row = mysql_fetch_array($result))
  {
  if ($row['mon']=="no"){
    echo "<tr style='color:grey'>";
  }
  elseif ($row['flag']==1 and $row['mon']=="yes"){
    echo "<tr style='color:red;' class='danger'>";
  } 
  else{echo "<tr>";}
  
  
  echo "<td>" . $row['CDN'] . "</td>";
  echo "<td>" . $row['Domain'] . "</td>";
  echo "<td>" . $row['Cname'] . "</td>";
  echo "<td>" . $row['CP'] . "</td>";
  echo "<td>" . $row['IPlist'] . "</td>";
  echo "<td>" . $row['mon'] . "</td>";
  printf('<td style=" text-align:center"> <input name="domain[]" type="checkbox" value="%s" />选中</td>',$row['Domain']);

  echo "</td></tr>";
  }

echo "</table>";

mysql_close($con);
echo '</form>';
?> 
</div>
</div>
</div>
